require 'bootstrap/js/dropdown.js'
require './../../../libs/styles/index.sass'

module.exports = angular.module 'index', [
  require('statusFilter').name
  require('commonFilter').name
]
.controller 'IndexCtrl', ($log, $scope, $state, $rootScope, $stateParams, Constant, AccountService, SessionService, AUTH_EVENTS)->
  $log.log "index controller init"
  constant = new Constant()
  accountService = new AccountService()
  sessionService = new SessionService()

  _config = ->
    $scope.qiNiuUrl = constant.QI_NIU_URL
  _load = ->
  _config()
  _load()
  $scope.logout = ->
    accountService.logout (response)->
      $rootScope.$broadcast AUTH_EVENTS.logoutSuccess

  $scope.toAccountManagePage = ->
    window.open "#{constant.PLATFORM.login.url}/#/index/account/list", "_blank"

  $scope.changeCity = ->
    findByCityId = (id)->
      return city for city in $rootScope.session.cities when city.id is id
    city = findByCityId $rootScope.session.currentCity.id
    sessionService.setCurrentCity city
    $state.transitionTo $state.current, $stateParams, {reload: true}
